#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   __init__.py
@Time    :   2024/01/22 11:40:01
@Author  :   chakcy 
@Email   :   947105045@qq.com
@description   :   初始化
'''

from rpa_tool.browser import Browser
from rpa_tool.log import log_init
from rpa_tool import data_table
from rpa_tool import file_operation
from rpa_tool import keyboard
from rpa_tool import clipboard
from rpa_tool.mouse import Mouse
from rpa_tool.email_module import Mail
from rpa_tool.message_window import *
from rpa_tool.screenshot import screenshot
from dependency_injector import containers, providers
import json

class RPAContainer(containers.DeclarativeContainer):

    config = providers.Configuration()
    
    browser = providers.Factory(
        Browser,
        isHeadless = config.browser_params["isHeadless"]
    )

    mail = providers.Factory(
        Mail,
        mail_host = config.mail_params["mail_host"],
        mail_pass = config.mail_params["mail_pass"],
        sender = config.mail_params["sender"],
        receivers = config.mail_params["receivers"]
    )

    mouse = providers.Factory(
        Mouse,
        pause = config.mouse_params["pause"],
        failsafe = config.mouse_params["failsafe"]
    )


def init(config_path:str):
    config_dict:dict = json.load(open(config_path, "r", encoding="utf-8"))
    config = config_dict.get("other_params", {})
    RPA_container = RPAContainer()
    RPA_container.config.from_dict(config_dict)
    return RPA_container, config
